from data import *
from model import *
import matplotlib as plt

max_features = 20000
maxlen = 200
train_dataset, val_dataset = read_imdb(max_features)

(train_ds, train_label), (val_ds, val_label) = train_dataset, val_dataset
train_ds = preprocessing.sequence.pad_sequences(train_ds, maxlen=maxlen)
val_ds = preprocessing.sequence.pad_sequences(val_ds, maxlen=maxlen)

model = lstm(max_features)
model.compile("adam", "binary_crossentropy", metrics=["accuracy"])
model_history = model.fit(train_ds, train_label, batch_size=32, epochs=10, validation_data=(val_ds, val_label))

loss = model_history.history['loss']
val_loss = model_history.history['val_loss']

epochs = range(10)

plt.figure()
plt.plot(epochs, loss, 'r', label='Training loss')
plt.plot(epochs, val_loss, 'bo', label='Validation loss')
plt.title('Training and Validation Loss')
plt.xlabel('Epoch')
plt.ylabel('Loss Value')
plt.ylim([0, 1])
plt.legend()
plt.show()